<template>
  <div>
    <!-- 登入人既录入人 - 行政应诉 -->
    <iframe v-if="iframeUrl" id="respondtIframe" :src="iframeUrl" width="100%" height="850vh" scrolling="yes" frameborder="0" />
    <!-- 干预行政复议弹框 -->
    <ApprovalDocPreview ref="approvalDocPreviewRef" />
  </div>
</template>

<script>
const SFNET_URL = process.env.VUE_APP_SFNET_URL
import { SFNET_APPKEY, SFNET_SECRETKEY } from '@/store/mutation-types'
import storage from 'store'
import { APP_USER, ACCESS_TOKEN } from '@/store/mutation-types.js'
import { queryTaskidByApplyid } from '@/api/apply/apl_main.js'
export default {
  data() {
    return {
      applyid: this.$route.params.applyid,
      matid: this.$route.params.matid,
      pattern: this.$route.params.pattern,
      sfnet_appKey: SFNET_APPKEY,
      sfnet_secretKey: SFNET_SECRETKEY,
      currentUser: storage.get(APP_USER), // 登录人信息
      iframeUrl: null,
    }
  },
  created() {
    const token = storage.get(ACCESS_TOKEN)
    // console.log('this.$route.params', this.$route.params)
    this.iframeUrl = `${SFNET_URL}/correctionApplyForm/add/100000_360100-000201000000-CRC-001-01/3/${this.currentUser.userId}/${SFNET_APPKEY}/${SFNET_SECRETKEY}/${token}`
    console.log('iframeUrl', this.iframeUrl)
  },
  beforeDestroy() {
    window.removeEventListener('message', this.eventGetApproveCurrentUser)
  },
  mounted() {
    window.addEventListener('message', this.eventGetApproveCurrentUser)
  },
  methods: {
    eventGetApproveCurrentUser(event) {
      console.log('申报端事件', event.data)
      if (event.data.operation == 'getApproveCurrentUser') {
        const iframeWindow = window.frames[0]
        iframeWindow.postMessage(
          {
            operation: 'setApproveCurrentUser',
            currentUser: this.currentUser,
          },
          '*'
        )
      } else if (event.data.operation == 'CorrectionPreview') {
        // 社矫预览操作按钮
        this.$refs.approvalDocPreviewRef.f_init(event.data.applyid, 'PUB_CORRECTION', event.data.body)
      } else if (event.data.operation == 'finishCorrect') {
        // 提交完成后跳转
        this.finishCorrect(event.data)
      }
    },
    async finishCorrect (record) {
      if (!record.applyid) {
        this.$message.error('回调参数缺失')
      }
      const queryParam = {
        toTabKey: '4'
      }
      // // 1. 查询流程的taskid
      // const { data } = await queryTaskidByApplyid(record.applyid)
      // // console.log('查询流程的taskid', data)
      // if (null == data) {
      //   this.$message.error('业务任务信息查询失败')
      // }
      this.$router.push({
        path: '/CondeployTodo',
        query: {
          url: '/CondeployTodo',
          queryParam: queryParam
        }
      })
    }
  },
  components: {
    ApprovalDocPreview: () => import('@/views/accept/ApprovalDocPreview.vue'),
  },
}
</script>

<style  scoped>
</style>